﻿using System.Collections.Generic;
using CivilRegistry.ControlledModel.Repository;

namespace CivilRegistry.ControlledModel
{
    /// <summary>
    /// The unsubscription object.
    /// </summary>
    public partial class Unsubscription
    {
        #region Local Fields

        /// <summary>
        /// Holds the <see cref="UnsubscriptionRepository"/> instance.
        /// </summary>
        static UnsubscriptionRepository repository = new UnsubscriptionRepository();

        #endregion

        #region Methods

        #region Finder Methods

        /// <summary>
        /// Finds the <see cref="Unsubscription"/> by Id.
        /// </summary>
        /// <param name="id">The id of the <see cref="Unsubscription"/>.</param>
        /// <returns>Found <see cref="Unsubscription"/> object, null if not found.</returns>
        public static Unsubscription FindById(int id)
        {
            return repository.FindBy(unsubscription => unsubscription.UnsubscriptionId == id);
        }

        /// <summary>
        /// Finds the <see cref="Unsubscription"/> by <see cref="User"/>.
        /// </summary>
        /// <param name="user">The <see cref="User"/>.</param>
        /// <param name="unsubscriptionType">The <see cref="UnsubscriptionType"/>.</param>
        /// <returns>Found <see cref="Unsubscription"/> object, null if not found.</returns>
        public static Unsubscription FindBy(User user, UnsubscriptionType unsubscriptionType)
        {
            return repository.FindBy(unsubscription => unsubscription.UnsubscribedUser == user && unsubscription.UnsubscriptionType == unsubscriptionType);
        }

        /// <summary>
        /// Finds all <see cref="Unsubscription"/>s.
        /// </summary>
        /// <returns>Found <see cref="Unsubscription"/> objects, empty if none are found.</returns>
        public static List<Unsubscription> FindAll()
        {
            List<Unsubscription> unsubscriptionList = new List<Unsubscription>();
            repository.FindAll().ForEach(unsubscription => unsubscriptionList.Add(unsubscription));
            return unsubscriptionList;
        }

        #region CUD Methods

        /// <summary>
        /// To insert the <see cref="Unsubscription"/>.
        /// </summary>
        /// <param name="unsubscription">The <see cref="Unsubscription"/> to insert.</param>
        /// <returns>The inserted <see cref="Unsubscription"/> object.</returns>
        internal static Unsubscription Insert(Unsubscription unsubscription)
        {
            return repository.Insert(unsubscription);
        }

        /// <summary>
        /// To update the <see cref="Unsubscription"/>.
        /// </summary>
        /// <param name="unsubscription">The <see cref="Unsubscription"/> to update.</param>
        /// <returns>The updated <see cref="Unsubscription"/> object.</returns>
        internal static Unsubscription Update(Unsubscription unsubscription)
        {
            return repository.Update(unsubscription);
        }

        /// <summary>
        /// To delete the <see cref="Unsubscription"/>.
        /// </summary>
        /// <param name="unsubscription">The <see cref="Unsubscription"/> to delete.</param>
        internal static void Delete(Unsubscription unsubscription)
        {
            repository.Delete(unsubscription);
        }

        #endregion

        #endregion

        #endregion
    }
}
